package com.springcloud.order.modular.order.controller;

import com.springcloud.commom.annotion.BusinessLog;
import com.springcloud.commom.api.R;
import com.springcloud.commom.enums.LogAnnotionOpTypeEnum;
import com.springcloud.order.modular.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.Date;

@RestController
@RequestMapping("buy")
@Validated
@Slf4j
public class BuyController {

    @Resource
    private OrderService orderService;

    @PostMapping("buyProduct")
    @BusinessLog(title = "购买商品", opType = LogAnnotionOpTypeEnum.ADD)
    public R<String> buyProduct(@NotNull String pid, @NotNull Integer num) {
        log.info("============buyProduct========pid:[{}]", pid);
        log.info("============buyProduct========num:[{}]", num);

        orderService.buyProduct(pid, num);

        return R.success();
    }

    public static void main(String[] args) {
        // 获取当前时间的时间戳
        long timestamp = System.currentTimeMillis();

        System.out.println("当前时间戳（毫秒）: " + timestamp);
    }
}
